// pages/admin_mgr/admin_mgr.js
const db = wx.cloud.database()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    adminName: '',
    adminPhone: '',
    orderCnt: 0,
    cinemaCnt: 0,
    movieCnt: 0,
    sessionCnt: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      adminName: options.adminName,
      adminPhone: options.adminPhone,
      orderCnt: 0,
      cinemaCnt: 0,
      movieCnt: 0,
      sessionCnt: 0
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  async onShow() {
    var that = this
    await db.collection('order_info').count().then(res => {
      that.setData({
        orderCnt: res.total
      })
    })
    await db.collection('cinema').count().then(res => {
      that.setData({
        cinemaCnt: res.total
      })
    })
    await db.collection('movies').count().then(res => {
      that.setData({
        movieCnt: res.total
      })
    })
    await db.collection('session_info').count().then(res => {
      that.setData({
        sessionCnt: res.total
      })
    })
  },

  exitAdminMgr() {
    wx.switchTab({
      url: '../me/me',
    })
  },

  modifyManagerPassword() {
    wx.navigateTo({
      url: '../modify_admin_password/modify_admin_password',
    })
  },

  cinemaManage() {
    wx.navigateTo({
      url: '/pages/cinema_mgr/cinema_mgr',
    })
  },

  movieManage() {
    wx.navigateTo({
      url: '/pages/movie_mgr/movie_mgr',
    })
  },

  purchaseManage() {
    wx.navigateTo({
      url: '/pages/purchase_mgr/purchase_mgr',
    })
  },

  sessionMgr(e) {
    var pageType = e.currentTarget.dataset.pagetype
    wx.navigateTo({
      url: `/pages/session_mgr/session_mgr`,
    })
  }
})